extends Node2D


@onready var top_pipe:    Area2D = get_node("top_pipe")
@onready var bottom_pipe: Area2D = get_node("bottom_pipe")
@onready var coin:    Area2D = get_node("coin")

var speed = 4
var end = -64
var start = 1344
var y_min = 164
var y_max = 440

func _ready():
	top_pipe.connect("area_entered", kill_player)
	bottom_pipe.connect("area_entered", kill_player)
	position.y = randi_range(y_min,y_max)

func _process(_delta):

	if (Global.player_dead):
		return

	position.x -= speed
	if position.x <= end:
		position.x = start
		position.y = randi_range(y_min, y_max)
		coin.show()
		coin.enable_hitbox()

func kill_player(area):
	if area.name == "player":
		Global.player_dead = true
